package cn.jsj.finance.bank;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.object.FrontWageInfo;
import cn.jsj.pojo.TblWageManage;
import cn.jsj.utils.SysLogger;

/**
 * 查询工资帐信息处理类
 * @author LI
 *
 */
 public class SearchWageInfo extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 	// 调试信息
		 	cn.jsj.utils.SysLogger.PrintInfo("查询工资信息");

		 	//获取参数
		 	String lawyerAssiName=request.getParameter("lawyerAssiName").trim();
		 	String enterWagePer=request.getParameter("enterWagePer").trim();
		 	lawyerAssiName=new String(lawyerAssiName.getBytes("ISO-8859-1"),"UTF-8");
		 	enterWagePer=new String(enterWagePer.getBytes("ISO-8859-1"),"UTF-8");

		 	//判断输入条件
		 	if(lawyerAssiName==null){
		 		lawyerAssiName="";
		 	}
		 	if(enterWagePer==null){
		 		enterWagePer="";
		 	}

			//获得参数：1.第几条开始。2.一页显示几条
			int startNumb=Integer.parseInt(request.getParameter("start"));
			int totalNumb=Integer.parseInt(request.getParameter("limit"));

			//调试信息
			cn.jsj.utils.SysLogger.PrintInfo("start---->"+startNumb+"   total--------->"+totalNumb+"   "+lawyerAssiName+"  "+enterWagePer);

			//新建后台到DB的工资参数对象
			cn.jsj.bgtodb.SearchWageInfoProperty swip=new cn.jsj.bgtodb.SearchWageInfoProperty(lawyerAssiName,enterWagePer,startNumb,totalNumb);

			//获得工资信息条数
			cn.jsj.dao.TblWageManageDAO twmd=new cn.jsj.dao.TblWageManageDAO();
			int wageNumber=twmd.getSearWageInfoNumb(swip);

			//调试信息
			cn.jsj.utils.SysLogger.PrintInfo("tiaoshu----->"+wageNumber);

			//工资信息列表
			java.util.List<TblWageManage> wageList=new java.util.LinkedList<TblWageManage>();
			wageList=twmd.getSearWageInfo(swip);


			//新建转化类对象
			 cn.jsj.object.rebuild.FrontWageInfoRebuild fwir=new cn.jsj.object.rebuild.FrontWageInfoRebuild();
			//转化成前台所需要的工资对象
			java.util.List<FrontWageInfo> frontWageInfoList=new java.util.LinkedList<FrontWageInfo>();
			//前台工资帐对象
			cn.jsj.object.FrontWageInfo fwi=new cn.jsj.object.FrontWageInfo();
			for(int i=0;i<wageList.size();i++){
				fwi=fwir.rebuildWageInfo(wageList.get(i));
				frontWageInfoList.add(fwi);
			}

			//转换成JSON型数据
			cn.jsj.utils.ProduceJsonData pjd=new cn.jsj.utils.ProduceJsonData();
			String jsonData=pjd.jsonFromList(frontWageInfoList, wageNumber);

			//调试信息
			SysLogger.PrintInfo(jsonData);
			//输出到客户端
			java.io.PrintWriter pw=response.getWriter();
			pw.println(jsonData);
			pw.flush();
			pw.close();


	}
}